package com.neuedu.javase.serializable;

import java.io.*;

/***
 * 项目名称:  MyJavaSE 
 * 包：  com.neuedu.javase.serializable 
 * date:   2025/11/6   9:41  
 * 描述:  
 *  @author : 张金山
 *  作者博客:   https://blog.fulfill.com.cn
 */
public class Runner {
    public static void write() {

        Teacher teacher = new Teacher("张三",18,9999.98,"哈尔滨","123456");
        System.out.println(teacher);


        //保存到teacher.obj
        try (ObjectOutputStream oos =  new ObjectOutputStream(new FileOutputStream("d:\\upload\\teacher.obj"))){

            oos.writeObject(teacher);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }

    public static void read() {



        //保存到teacher.obj
        try (ObjectInputStream oos =  new ObjectInputStream(new FileInputStream("d:\\upload\\teacher.obj"))){

            Teacher teacher = (Teacher) oos.readObject();
            System.out.println(teacher);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }


    }

    public static void main(String[] args) {
        write();//张三  序列化

        read();  //李四  返序列化
    }
}
